package org.meow.controller.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.meow.entity.ArticleGroup;
import org.meow.result.Result;
import org.meow.service.ArticleCateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * &#064;Date: 24/05/16-13:50
 * &#064;Description:
 */
@RestController
@RequestMapping("/api/article/cate")
@Tag(name = "API接口")
public class ArticleCateApi {

  @Autowired
  private ArticleCateService articleCateService;

  @GetMapping("/{id}")
  @Operation(summary = "获取指定id文章分类")
  public Result<Object> getArticleCateById(@PathVariable Integer id) {
    ArticleGroup articleGroup = articleCateService.getArticleGroupById(id);
    return articleGroup == null ? Result.error("该文章分类不存在") : Result.success(articleGroup);
  }

  @GetMapping
  @Operation(summary = "获取所有文章分类")
  public Result<List<ArticleGroup>> getArticleGroup() {
    return Result.success(articleCateService.getArticleGroup());
  }

}
